<script setup lang="ts">
import { getAchievTransDetail } from "@/api/research/achievTrans";
import { FileUpload } from "@/components/common/FileUpload";
import { formatDate, isCanPreview } from "@/utils/common";
import { ref, watch } from "vue";
import { FormProps } from "../utils/types";
const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: null,
    title: "新增",
    acquisitionCompany: "",
    acquisitionFiles: "",
    acquisitionPrice: "",
    acquisitionDate: "",
    rewardLevel: "",
    firstInventor: "",
    firstInventorType: "",
    outId: undefined,
    patentName: "",
    patentType: "",
    patentee: "",
    score: undefined,
    secondInventor: "",
    secondInventorType: "",
    examineStatus: 0,
    examineDesc: ""
  }),
  dataId: null,
  userList: null
});

watch(
  () => props.dataId,
  async newValue => {
    if (!newValue) {
      return;
    }
    getAchievTransDetail({ id: newValue }).then(res => {
      newFormInline.value = res.data;
    });
  },
  { immediate: true }
);

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    label-width="160px"
    :inline="true"
    class="add-form"
  >
    <el-form-item label="专利名称" prop="patentName">
      <div>{{ newFormInline.patentName || "--" }}</div>
    </el-form-item>
    <el-form-item label="专利类型" prop="patentType">
      <div>{{ newFormInline.patentType || "--" }}</div>
    </el-form-item>
    <el-form-item label="专利权人" prop="patentee">
      <div>{{ newFormInline.patentee || "--" }}</div>
    </el-form-item>
    <el-form-item />
    <el-form-item label="第一发明人类型" prop="firstInventorType">
      <div>{{ newFormInline.firstInventorType || "--" }}</div>
    </el-form-item>
    <el-form-item label="第一发明人" prop="firstInventor">
      <div>{{ newFormInline.firstInventor || "--" }}</div>
    </el-form-item>
    <el-form-item label="受让企业" prop="acquisitionCompany">
      <div>{{ newFormInline.acquisitionCompany || "--" }}</div>
    </el-form-item>
    <el-form-item label="转让金额" prop="acquisitionPrice">
      <div>
        <!-- {{ newFormInline.acquisitionPrice || "--" }} -->
        {{
          newFormInline.acquisitionPrice
            ? Number(newFormInline.acquisitionPrice) / 100
            : "--"
        }}
        <span v-if="newFormInline.acquisitionPrice">万元</span>
      </div>
    </el-form-item>
    <el-form-item label="转让合同签订日期" prop="acquisitionDate">
      {{ formatDate(newFormInline.acquisitionDate) }}
    </el-form-item>
    <el-form-item label="转让合同" prop="acquisitionFiles">
      <FileUpload
        v-model="newFormInline.acquisitionFiles"
        :isCanPreview="isCanPreview(newFormInline, props.dataId)"
        disabled
      />
    </el-form-item>

    <el-form-item label="获取积分" prop="score">
      <div>{{ newFormInline.score || "--" }}</div>
    </el-form-item>
    <el-form-item />
    <el-form-item label="审核状态" prop="score">
      <el-tag v-if="newFormInline.examineStatus === 0" type="warning"
        >审核中</el-tag
      >
      <el-tag v-else-if="newFormInline.examineStatus === 1" type="primary"
        >已审核</el-tag
      >
      <el-tag v-else type="danger">已驳回</el-tag>
    </el-form-item>
    <el-form-item label="驳回原因" prop="score">
      <div>{{ newFormInline.examineDesc || "--" }}</div>
    </el-form-item>
    <el-form-item />
  </el-form>
</template>
<style lang="scss" scoped>
.add-form {
  text-align: center;
  .el-form-item {
    width: 42%;
  }
}
</style>
